package org.bee.controller;

import org.bee.ResultTool;
import org.bee.json.JsonUtils;
import org.bee.model.DictEnums;
import org.bee.model.result.Result;
import org.bee.redis.RedisUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 枚举字典
 */
@RestController
@RequestMapping("/enumDict")
public class EnumController {

    private final RedisUtils redisUtils;

    public EnumController(RedisUtils redisUtils) {
        this.redisUtils = redisUtils;
    }

    /**
     * 获取枚举字典
     * @param code 字典码
     * @return 字典
     */
    @GetMapping("/getDict")
    public Result getDict(String code){
        Result result = ResultTool.success();
        String dict = (String) redisUtils.get(code);
        DictEnums dictEnums = JsonUtils.fromJson(dict, DictEnums.class);
        result.setData(dictEnums);
        return result;
    }
}
